/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef HKS_ACCESS_CONTROL_TEST_COMMON_H
#define HKS_ACCESS_CONTROL_TEST_COMMON_H

#include <vector>

#include "hks_three_stage_test_common.h"
#include "time_service_client.h"

#define SHA256_SIGN_LEN 32
#define SHA256_KEY_LEN 32
#define AUTH_TOKEN_LEN sizeof(UserAuthTokenHal)
#define AUTH_TOKEN_DATA_LEN (AUTH_TOKEN_LEN - SHA256_SIGN_LEN)
#define TOKEN_CHALLENGE_LEN 32
#define HKS_DEFAULT_USER_AT_KEY "huks_default_user_auth_token_key"

struct UserAuthTokenHal {
    uint32_t version = 0;
    uint8_t challenge[TOKEN_CHALLENGE_LEN];
    uint64_t secureUid;
    uint64_t enrolledId;
    uint64_t credentialId = 0;
    uint64_t time;
    uint32_t authTrustLevel = 0;
    uint32_t securityLevel = 0;
    uint8_t sign[SHA256_SIGN_LEN];
};

#ifdef __cplusplus
extern "C" {
#endif

int32_t AuthTokenImportKey();
//If time = 0, function will set the correct time automatically
int32_t AuthTokenSign(struct HksBlob *challenge, uint64_t secureUid, uint64_t enrolledId, uint64_t time, std::vector<uint8_t>& token);

#ifdef __cplusplus
}
#endif

#endif // HKS_THREE_STAGE_TEST_COMMON_H